package com.avic.rong.questionOrAnswer.activity;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.avic.rong.BaseActivity;
import com.avic.rong.MainActivity;
import com.avic.rong.R;
import com.avic.rong.activity.login.LoginPhoneActivity;
import com.avic.rong.activity.mine.MyFansActivity;
import com.avic.rong.activity.mine.OwnMessageActivity;
import com.avic.rong.activity.product.OnlineCServiceActivity;
import com.avic.rong.api.focus_fans.FocusStateApi;
import com.avic.rong.bean.CartListReloadEvent;
import com.avic.rong.bean.GoCartListEvent;
import com.avic.rong.bean.HomePageEvent;
import com.avic.rong.bean.MinePageEvent;
import com.avic.rong.questionOrAnswer.adapter.PersonHomeVpAdapter;
import com.avic.rong.questionOrAnswer.api.GetInfoApi;
import com.avic.rong.questionOrAnswer.bean.HomeInfoBean;
import com.avic.rong.questionOrAnswer.fragment.ArticleFragment;
import com.avic.rong.questionOrAnswer.fragment.QuestionOrAnswerFragment;
import com.avic.rong.questionOrAnswer.fragment.TrainFragment;
import com.avic.rong.questionOrAnswer.fragment.VideoPersonalFragment;
import com.avic.rong.shoppingCar.activity.ShoppingCarActivity;
import com.avic.rong.utils.ConstantsUtils;
import com.avic.rong.utils.GlideUtils;
import com.avic.rong.utils.SharedPreferencesUtil;
import com.avic.rong.utils.StatusBarUtil;
import com.avic.rong.utils.ToastTools;
import com.bumptech.glide.Glide;
import com.example.minato.minastore.BaseResultEntity;
import com.example.minato.minastore.http.HttpManager;
import com.example.minato.minastore.listener.HttpOnNextListener;
import com.flyco.tablayout.SlidingTabLayout;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import cn.bingoogolapple.swipebacklayout.BGASwipeBackHelper;

public class PersonalHomeActivity extends BaseActivity implements BGASwipeBackHelper.Delegate, OnRefreshListener, OnLoadMoreListener {


    @BindView(R.id.tv_focuson)
    TextView tv_focuson;

    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.iv_search)
    ImageView ivSearch;
    @BindView(R.id.iv_right)
    ImageView ivRight;
    @BindView(R.id.ll_root)
    LinearLayout llRoot;
    @BindView(R.id.ic_photo)
    ImageView icPhoto;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_look_details)
    TextView tvLookDetails;
    @BindView(R.id.tv_edit_infor)
    TextView tvEditInfor;
    @BindView(R.id.tv_apply_renzheng)
    TextView tvApplyRenzheng;
    @BindView(R.id.tv_renzheng)
    TextView tvRenzheng;
    @BindView(R.id.tv_jianjie)
    TextView tvJianjie;
    @BindView(R.id.tv_fabu_num)
    public TextView tvFabuNum;
    @BindView(R.id.ll_fabu)
    LinearLayout llFabu;
    @BindView(R.id.tv_attention_sum)
    TextView tvAttentionSum;
    @BindView(R.id.ll_attention)
    LinearLayout llAttention;
    @BindView(R.id.tv_fans_sum)
    public TextView tvFansSum;
    @BindView(R.id.ll_fans)
    LinearLayout llFans;
    @BindView(R.id.tv_zan_sum)
    TextView tvZanSum;
    @BindView(R.id.ll_zan)
    LinearLayout llZan;
    @BindView(R.id.tab_layout)
    SlidingTabLayout tabLayout;
    @BindView(R.id.view_pager)
    ViewPager viewPager;
//    @BindView(R.id.loading_layout)
//    LoadingLayout loading_layout;
    @BindView(R.id.tab_layout_top)
    SlidingTabLayout tabLayoutTop;
    @BindView(R.id.scroll)
    NestedScrollView scroll;
    @BindView(R.id.ll_top_title)
    LinearLayout ll_top_title;
    @BindView(R.id.view)
    View view;
    @BindView(R.id.refreshLayout)
    public SmartRefreshLayout refreshLayout;

    @BindView(R.id.iv_attestation)
    ImageView iv_attestation;


    //    @BindView(R.id.search_sv_view)
//    AnimationNestedScrollView searchSvView;
    private PopupWindow popupWindow;

    private ArrayList<String> titleList = new ArrayList<>();
    private ArrayList<Fragment> fragmentsList = new ArrayList<>();
    private final String[] mTitles = {"文章", "问答", "培训", "视频"};

    private float LL_SEARCH_MIN_TOP_MARGIN, LL_SEARCH_MAX_TOP_MARGIN, LL_SEARCH_MAX_WIDTH, LL_SEARCH_MIN_WIDTH, TV_TITLE_MAX_TOP_MARGIN;
    private ViewGroup.MarginLayoutParams searchLayoutParams, titleLayoutParams;
    public String LOGO = null;
    private String NAME = null;
    private String AuthenticationInformation = null;
    private int ISV;

    private List<HomeInfoBean> listData;

    //目标项是否在最后一个可见项之后
    private boolean mShouldScroll;
    //记录目标项位置
    private int mToPosition;

    private String homeUserID;
    private String enterType;
    private BGASwipeBackHelper mSwipeBackHelper;
    private View popView;

    private HomeInfoBean.DataBean data;
    //切换到当前fragment的索引
    private int switchFragmentPostion = 0;

    private Runnable runnable = new Runnable() {

        @Override
        public void run() {
            scroll.scrollTo(0, 750);// 改变滚动条的位置
        }
    };

  /*  @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView();

        ButterKnife.bind(this);



        initView();
        addListener();

        initSwipeBackFinish();
        overridePendingTransition(R.anim.slide_in_right, R.anim.keep);

        //设置状态栏颜色
        StatusBarUtil.setStatusBarColor(this, getResources().getColor(R.color.color_3e3c4a));
    }*/


    protected void initView() {
        initSwipeBackFinish();
        overridePendingTransition(R.anim.slide_in_right, R.anim.keep);

        //设置状态栏颜色
        StatusBarUtil.setStatusBarColor(this, getResources().getColor(R.color.color_3e3c4a));
        homeUserID = getIntent().getStringExtra("homeUserID");
        if (SharedPreferencesUtil.getUserID().equals(homeUserID)) {
            tvEditInfor.setVisibility(View.VISIBLE);
            tv_focuson.setVisibility(View.GONE);
        } else if (!TextUtils.isEmpty(homeUserID)) {
            tvEditInfor.setVisibility(View.GONE);
            tv_focuson.setVisibility(View.VISIBLE);
        } else {
            tvEditInfor.setVisibility(View.VISIBLE);
            tv_focuson.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(getIntent().getStringExtra("enterType"))) {
            enterType = getIntent().getStringExtra("enterType");
        }

        titleList.add("文章");
        titleList.add("问答");
        titleList.add("成果");
        titleList.add("视频");

        Bundle bundle = new Bundle();
        bundle.putString("homeUserID", homeUserID);
        ArticleFragment articleFragment = new ArticleFragment();
        articleFragment.setArguments(bundle);
        QuestionOrAnswerFragment questionOrAnswerFragment = new QuestionOrAnswerFragment();
        questionOrAnswerFragment.setArguments(bundle);
//        AchievementFragment achievementFragment = new AchievementFragment();
//        achievementFragment.setArguments(bundle);
        TrainFragment trainFragment = new TrainFragment();
        trainFragment.setArguments(bundle);
        VideoPersonalFragment videoPersonalFragment = new VideoPersonalFragment();
        videoPersonalFragment.setArguments(bundle);

        fragmentsList.add(articleFragment);
        fragmentsList.add(questionOrAnswerFragment);
        fragmentsList.add(trainFragment);
        fragmentsList.add(videoPersonalFragment);
        refreshLayout.setOnRefreshListener(this);
        refreshLayout.setOnLoadMoreListener(this);

        PersonHomeVpAdapter personHomeVpAdapter = new PersonHomeVpAdapter(getSupportFragmentManager(), titleList, fragmentsList);
        viewPager.setAdapter(personHomeVpAdapter);
        tabLayout.setViewPager(viewPager, mTitles);
        tabLayoutTop.setViewPager(viewPager, mTitles);
        if (!TextUtils.isEmpty(enterType) && enterType.equals("1")) {
            viewPager.setCurrentItem(1);
        }
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {//当前页
                switchFragmentPostion = position;
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });


        homeContent();


//        LL_SEARCH_MIN_TOP_MARGIN = ScreenUtils.dp2px(this, 27f);//布局关闭时顶部距离
//        LL_SEARCH_MAX_TOP_MARGIN = ScreenUtils.dp2px(this, 270f);//布局默认展开时顶部距离
//        LL_SEARCH_MAX_WIDTH = ScreenUtils.getScreenWidth(this) - ScreenUtils.dp2px(this, 30f);//布局默认展开时的宽度
//        LL_SEARCH_MIN_WIDTH = ScreenUtils.getScreenWidth(this) - ScreenUtils.dp2px(this, 82f);//布局关闭时的宽度
//        TV_TITLE_MAX_TOP_MARGIN = ScreenUtils.dp2px(this, 11.5f);

    }


    private void homeContent() {

        Map<String, String> map = new HashMap<>();
        if (!SharedPreferencesUtil.getLoginToken().isEmpty()) {
            map.put("token", SharedPreferencesUtil.getLoginToken());
        } else {
            map.put("token", "");
        }

        if (TextUtils.isEmpty(homeUserID)) {
            map.put("userId", "");
        } else {
            map.put("userId", homeUserID);
        }
        final GetInfoApi getInfoApi = new GetInfoApi(this, simpleOnNextListener);
        getInfoApi.setCache(false);
        getInfoApi.setMap(map);
        HttpManager.getInstance().doHttpDeal(getInfoApi);

//        loading_layout.setOnReloadListener(new LoadingLayout.OnReloadListener() {
//            @Override
//            public void onReload(View v) {
//                HttpManager.getInstance().doHttpDeal(getInfoApi);
//                loading_layout.setStatus(LoadingLayout.LOADING);
//            }
//
//            @Override
//            public void onReturn(View v) {
//                onBackPressed();
//            }
//        });
//        loading_layout.setStatus(LoadingLayout.LOADING);




         /*else {
            loading_layout.setStatus(LoadingLayout.EMPTY);
        }*/
    }


    protected void addListener() {

      /*  ivRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showPopup(PersonalHomeActivity.this, llRoot);
            }
        });*/

        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        llZan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                zanDialog();

            }
        });
        llAttention.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                startActivity(MyFansActivity.queryIntent(PersonalHomeActivity.this, 0, homeUserID, getNAME()));
            }
        });
        llFans.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(MyFansActivity.queryIntent(PersonalHomeActivity.this, 1, homeUserID, getNAME()));

            }
        });
        tvEditInfor.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(OwnMessageActivity.queryIntent(PersonalHomeActivity.this));
            }
        });

        tv_focuson.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (SharedPreferencesUtil.isLogin()) {
                    FocusStateApi focusStateApi = new FocusStateApi(PersonalHomeActivity.this, new FocusStateListener(data));
                    focusStateApi.setArgument(Integer.valueOf(homeUserID), SharedPreferencesUtil.getLoginToken());
                    HttpManager.getInstance().doHttpDeal(focusStateApi);
                } else {
                    startActivity(LoginPhoneActivity.queryIntent(PersonalHomeActivity.this));
                }

            }
        });

        scroll.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            @Override
            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {

                if (scrollY > oldScrollY) {
                    Log.e("=====", "下滑");
                    Log.e("=====", "scrollY===" + scrollY);
                    Log.e("=====", "oldScrollY===" + oldScrollY);

                    if (scrollY >= 750) {
                        tabLayout.setVisibility(View.GONE);
                        tabLayoutTop.setVisibility(View.VISIBLE);
                        ll_top_title.setBackgroundColor(getResources().getColor(R.color.white));
                        ivBack.setImageResource(R.mipmap.ic_back_black);
                        ivRight.setImageResource(R.mipmap.ic_function_black);
                        LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) view.getLayoutParams(); //取控件textView当前的布局参数
                        linearParams.height = 130;// 控件的高强制设成20
                        view.setLayoutParams(linearParams);
                    }
                }
                if (scrollY < oldScrollY) {
                    Log.e("=====", "上滑");
                    Log.e("=====", "scrollY===" + scrollY);
                    Log.e("=====", "oldScrollY===" + oldScrollY);
                    if (scrollY < 750) {
                        tabLayout.setVisibility(View.VISIBLE);
                        tabLayoutTop.setVisibility(View.INVISIBLE);
                        ll_top_title.setBackgroundColor(getResources().getColor(R.color.color_3e3c4a));
                        ivBack.setImageResource(R.mipmap.icon_return);
                        ivRight.setImageResource(R.mipmap.gouwuche_dot);
                        LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) view.getLayoutParams(); //取控件textView当前的布局参数
                        linearParams.height = 0;// 控件的高强制设成20
                        view.setLayoutParams(linearParams);
                    }


                }

                if (scrollY == 0) {
                    Log.e("=====", "滑倒顶部");
                    Log.e("=====", "scrollY===" + scrollY);

                }

                if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight())) {
                    Log.e("=====", "滑倒底部");
                    Log.e("=====", "scrollY===" + scrollY);
                }
            }
        });
        llFabu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //防止滑动遮挡
//                view.setMinimumHeight(60);

                LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) view.getLayoutParams(); //取控件textView当前的布局参数
                linearParams.height = 130;// 控件的高强制设成20
                view.setLayoutParams(linearParams);

                Handler handler = new Handler();
                handler.postDelayed(runnable, 200);
            }
        });


//        searchSvView.setOnAnimationScrollListener(new AnimationNestedScrollView.OnAnimationScrollChangeListener() {
//            @Override
//            public void onScrollChanged(float dy) {
//                float searchLayoutNewTopMargin = LL_SEARCH_MAX_TOP_MARGIN - dy;
//                float searchLayoutNewWidth = LL_SEARCH_MAX_WIDTH - dy * 1.3f;//此处 * 1.3f 可以设置搜索框宽度缩放的速率
//
//                float titleNewTopMargin = (float) (TV_TITLE_MAX_TOP_MARGIN - dy * 0.5);
//
//                //处理布局的边界问题
//                searchLayoutNewWidth = searchLayoutNewWidth < LL_SEARCH_MIN_WIDTH ? LL_SEARCH_MIN_WIDTH : searchLayoutNewWidth;
//
//                if (searchLayoutNewTopMargin < LL_SEARCH_MIN_TOP_MARGIN) {
//                    searchLayoutNewTopMargin = LL_SEARCH_MIN_TOP_MARGIN;
//                }
//
//                if (searchLayoutNewWidth < LL_SEARCH_MIN_WIDTH) {
//                    searchLayoutNewWidth = LL_SEARCH_MIN_WIDTH;
//                }
//
//                float titleAlpha = 255 * titleNewTopMargin / TV_TITLE_MAX_TOP_MARGIN;
//                if (titleAlpha < 0) {
//                    titleAlpha = 0;
//                }
//
//                //设置相关控件的LayoutParams  此处使用的是MarginLayoutParams，便于设置params的topMargin属性
//                tvTitle.setTextColor(tvTitle.getTextColors().withAlpha((int) titleAlpha));
//                titleLayoutParams.topMargin = (int) titleNewTopMargin;
//                tvTitle.setLayoutParams(titleLayoutParams);
//
//                searchLayoutParams.topMargin = (int) searchLayoutNewTopMargin;
//                searchLayoutParams.width = (int) searchLayoutNewWidth;
//                tabLayout.setLayoutParams(searchLayoutParams);
//            }
//        });

    }

    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {

        if (switchFragmentPostion == 0) {
            if (fragmentsList.get(switchFragmentPostion) instanceof ArticleFragment) {
                ((ArticleFragment) fragmentsList.get(switchFragmentPostion)).onLoadMore();
            }
        } else if (switchFragmentPostion == 1) {
            if (fragmentsList.get(switchFragmentPostion) instanceof QuestionOrAnswerFragment) {
                ((QuestionOrAnswerFragment) fragmentsList.get(switchFragmentPostion)).onLoadMore();
            }
        } else if (switchFragmentPostion == 2) {
            if (fragmentsList.get(switchFragmentPostion) instanceof TrainFragment) {
                ((TrainFragment) fragmentsList.get(switchFragmentPostion)).onLoadMore();
            }
        } else if (switchFragmentPostion == 3) {
            if (fragmentsList.get(switchFragmentPostion) instanceof VideoPersonalFragment) {
                ((VideoPersonalFragment) fragmentsList.get(switchFragmentPostion)).onLoadMore();
            }
        }
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {
        //下拉刷新个人主页数据
        homeContent();

        if (switchFragmentPostion == 0) {
            if (fragmentsList.get(switchFragmentPostion) instanceof ArticleFragment) {
                ((ArticleFragment) fragmentsList.get(switchFragmentPostion)).onRefresh();
            }
        } else if (switchFragmentPostion == 1) {
            if (fragmentsList.get(switchFragmentPostion) instanceof QuestionOrAnswerFragment) {
                ((QuestionOrAnswerFragment) fragmentsList.get(switchFragmentPostion)).onRefresh();
            }
        } else if (switchFragmentPostion == 2) {
            if (fragmentsList.get(switchFragmentPostion) instanceof TrainFragment) {
                ((TrainFragment) fragmentsList.get(switchFragmentPostion)).onRefresh();
            }
        } else if (switchFragmentPostion == 3) {
            if (fragmentsList.get(switchFragmentPostion) instanceof VideoPersonalFragment) {
                ((VideoPersonalFragment) fragmentsList.get(switchFragmentPostion)).onRefresh();
            }
        }
    }

    public class FocusStateListener extends HttpOnNextListener<BaseResultEntity> {

        HomeInfoBean.DataBean data;

        public FocusStateListener(HomeInfoBean.DataBean data) {
            this.data = data;
        }

        @Override
        public void onNext(BaseResultEntity baseResultEntity) {
            if (baseResultEntity.getCode().equals(ConstantsUtils.STATUS_SUCCESS_200)) {
                if (data.getFollow()) {
                    tv_focuson.setText("＋ 关注");
                    tv_focuson.setTextColor(getResources().getColor(R.color.white));
                    tv_focuson.setSelected(false);
                    data.setFollow(false);
                    ToastTools.showToast(PersonalHomeActivity.this, "取消关注成功");
                } else {
                    tv_focuson.setText("已关注");
                    tv_focuson.setTextColor(getResources().getColor(R.color.color_98c72f));
                    tv_focuson.setSelected(true);
                    data.setFollow(true);
                    ToastTools.showToast(PersonalHomeActivity.this, "关注成功");
                }
            } else {
                ToastTools.showToast(PersonalHomeActivity.this, baseResultEntity.getMsg());
            }
        }
    }

    private void zanDialog() {
        View inflate = getLayoutInflater().inflate(R.layout.zan_dialog_layout, null);
        TextView tv_affirm = inflate.findViewById(R.id.tv_affirm);
        TextView tv_zan_num = inflate.findViewById(R.id.tv_zan_num);
        TextView tv_name = inflate.findViewById(R.id.tv_name);
        if (listData != null && listData.size() > 0) {
            HomeInfoBean.DataBean data = listData.get(0).getData();
            tv_zan_num.setText(data.getThumbNum() + "");
            HomeInfoBean.DataBean infoData = listData.get(1).getData();
            tv_name.setText(infoData.getUserName());
        }
        tv_affirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });
        commonPop(inflate);
    }

    //融融号主页发布等数据
    HttpOnNextListener simpleOnNextListener = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {

            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_200)) {
                ToastTools.showToast(PersonalHomeActivity.this, subjects.getMsg());
                return;
            }
//            loading_layout.setStatus(LoadingLayout.SUCCESS);
            listData = (List<HomeInfoBean>) subjects.getData();
            data = listData.get(0).getData();
            if (data != null) {
                tvAttentionSum.setText(data.getFollowNum() + "");
                tvZanSum.setText(data.getThumbNum() + "");
                tvFansSum.setText(data.getFollowedNum() + "");
                tvFabuNum.setText(data.getPublicNum() + "");
                if (!TextUtils.isEmpty(homeUserID)) {
                    if (data.getFollow()) {
                        tv_focuson.setText("已关注");
                        tv_focuson.setTextColor(getResources().getColor(R.color.color_98c72f));
                        tv_focuson.setSelected(true);
                    } else {
                        tv_focuson.setText("+  关注");
                        tv_focuson.setTextColor(getResources().getColor(R.color.white));
                        tv_focuson.setSelected(false);
                    }
                }
                setISV(data.getIsV());
                if (1 == data.getIsV()) {
                    iv_attestation.setVisibility(View.VISIBLE);
                }

            }
            HomeInfoBean.DataBean infoData = listData.get(1).getData();
            if (infoData != null) {
                LOGO = infoData.getLogo();

                setLOGO(infoData.getLogo());
                setNAME(infoData.getUserName());
                setAuthenInfo(infoData.getAuthenticationInformation());
                if (TextUtils.isEmpty(infoData.getLogo())) {
                    Glide.with(PersonalHomeActivity.this).load(R.mipmap.ic_default_head).into(icPhoto);
                } else {
                    GlideUtils.loaderHanldeRoundImage(PersonalHomeActivity.this, infoData.getLogo(), icPhoto, 110);
                }
                tvName.setText(infoData.getUserName());
                if (!TextUtils.isEmpty(infoData.getUserDesc())){
                    tvJianjie.setText(infoData.getUserDesc().replaceAll("[\\t\\n\\r]"," "));//简介
                }else{
                    tvJianjie.setText("");//简介
                }

                tvRenzheng.setText(infoData.getAuthenticationInformation()); //认证

            }

        }


        @Override
        public void onCacheNext(String cache) {


        }


        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
//            if (e instanceof SocketTimeoutException || e instanceof ConnectException) {
//                loading_layout.setStatus(LoadingLayout.NO_NETWORK);
//            } else {
//                loading_layout.setStatus(LoadingLayout.ERROR);
//            }
        }
    };

    public String getLOGO() {
        return LOGO;
    }

    public void setLOGO(String LOGO) {
        this.LOGO = LOGO;
    }

    public String getNAME() {
        return NAME;
    }

    public void setNAME(String NAME) {
        this.NAME = NAME;
    }
    public String getAuthenticationInformation() {
        return AuthenticationInformation;
    }

    public void setAuthenInfo(String authenticationInformation) {
        this.AuthenticationInformation = authenticationInformation;
    }

    public int getISV() {
        return ISV;
    }

    public void setISV(int ISV) {
        this.ISV = ISV;
    }

    private void commonPop(View view) {
        popupWindow = new PopupWindow(view, ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.WRAP_CONTENT, false);
        // 产生背景变暗效果
        WindowManager.LayoutParams lp = getWindow()
                .getAttributes();
        lp.alpha = 0.4f;
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        getWindow().setAttributes(lp);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.setOutsideTouchable(false);
//        popupWindow.setTouchable(true);
        //从下往上弹出动画效果
//        popupWindow.setAnimationStyle(R.style.bottomPopupAnimation);
        popupWindow.showAtLocation(findViewById(R.id.ll_root), Gravity.CENTER, 0, 0);
        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

            // 在dismiss中恢复透明度
            public void onDismiss() {
                WindowManager.LayoutParams lp = getWindow()
                        .getAttributes();
                lp.alpha = 1f;
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
                getWindow().setAttributes(lp);
            }
        });
    }

    /**
     * 平滑的滑动到指定位置
     */
    private void smoothMoveToPosition(RecyclerView mRecyclerView, final int position) {
        // 第一个可见位置
        int firstItem = mRecyclerView.getChildLayoutPosition(mRecyclerView.getChildAt(0));
        // 最后一个可见位置
        int lastItem = mRecyclerView.getChildLayoutPosition(mRecyclerView.getChildAt(mRecyclerView.getChildCount() - 1));
        if (position < firstItem) {
            // 第一种可能:跳转位置在第一个可见位置之前
            mRecyclerView.smoothScrollToPosition(position);
        } else if (position <= lastItem) {
            // 第二种可能:跳转位置在第一个可见位置之后
            int movePosition = position - firstItem;
            if (movePosition >= 0 && movePosition < mRecyclerView.getChildCount()) {
                int top = mRecyclerView.getChildAt(movePosition).getTop();
                mRecyclerView.smoothScrollBy(0, top);
            }
        } else {
            // 第三种可能:跳转位置在最后可见项之后
            mRecyclerView.smoothScrollToPosition(position);
            mToPosition = position;
            mShouldScroll = true;
        }
    }

    /**
     * 初始化滑动返回。在 super.onCreate(savedInstanceState) 之前调用该方法
     */
    private void initSwipeBackFinish() {
        mSwipeBackHelper = new BGASwipeBackHelper(this, this);

        // 「必须在 Application 的 onCreate 方法中执行 BGASwipeBackHelper.init 来初始化滑动返回」
        // 下面几项可以不配置，这里只是为了讲述接口用法。

        // 设置滑动返回是否可用。默认值为 true
        mSwipeBackHelper.setSwipeBackEnable(true);
        // 设置是否仅仅跟踪左侧边缘的滑动返回。默认值为 true
        mSwipeBackHelper.setIsOnlyTrackingLeftEdge(true);
        // 设置是否是微信滑动返回样式。默认值为 true
        mSwipeBackHelper.setIsWeChatStyle(true);
        // 设置阴影资源 id。默认值为 R.drawable.bga_sbl_shadow
        mSwipeBackHelper.setShadowResId(R.drawable.bga_sbl_shadow);
        // 设置是否显示滑动返回的阴影效果。默认值为 true
        mSwipeBackHelper.setIsNeedShowShadow(true);
        // 设置阴影区域的透明度是否根据滑动的距离渐变。默认值为 true
        mSwipeBackHelper.setIsShadowAlphaGradient(true);
        // 设置触发释放后自动滑动返回的阈值，默认值为 0.3f
        mSwipeBackHelper.setSwipeBackThreshold(0.3f);
        // 设置底部导航条是否悬浮在内容上，默认值为 false
        mSwipeBackHelper.setIsNavigationBarOverlap(false);
    }

    /**
     * 是否支持滑动返回。这里在父类中默认返回 true 来支持滑动返回，如果某个界面不想支持滑动返回则重写该方法返回 false 即可
     *
     * @return
     */
    @Override
    public boolean isSupportSwipeBack() {
        return true;
    }

    /**
     * 正在滑动返回
     *
     * @param slideOffset 从 0 到 1
     */
    @Override
    public void onSwipeBackLayoutSlide(float slideOffset) {
    }

    /**
     * 没达到滑动返回的阈值，取消滑动返回动作，回到默认状态
     */
    @Override
    public void onSwipeBackLayoutCancel() {
    }

    /**
     * 滑动返回执行完毕，销毁当前 Activity
     */
    @Override
    public void onSwipeBackLayoutExecuted() {
        mSwipeBackHelper.swipeBackward();
    }

    @Override
    public void onBackPressed() {
        // 正在滑动返回的时候取消返回按钮事件

        if (mSwipeBackHelper.isSliding()) {
            return;
        }
        mSwipeBackHelper.backward();
        overridePendingTransition(R.anim.keep, R.anim.out_from_right);
    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(R.anim.keep, R.anim.out_from_right);
    }

    protected void showPopup(RxAppCompatActivity baseActivity, View view) {
        commPop(view);
        initListener(baseActivity);
    }

    ;

    /*
     * 功能直达蒙层
     * */
    private void commPop(View view) {
        popView = LayoutInflater.from(this).inflate(R.layout.function_of_direct, null, false);
        popupWindow = new PopupWindow(popView, ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.WRAP_CONTENT, true);
       /* // 产生背景变暗效果
        WindowManager.LayoutParams lp = getWindow()
                .getAttributes();
        lp.alpha = 0.4f;
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        getWindow().setAttributes(lp);*/
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.setOutsideTouchable(true);
        popupWindow.setTouchable(true);
        popupWindow.setClippingEnabled(false);
        //从上往下弹出动画效果
        popupWindow.setAnimationStyle(R.style.topPopupAnimation);
        popupWindow.showAtLocation(view, Gravity.TOP, 0, 0);
    }

    private void initListener(Context context) {
        ImageView img_close_pop = popView.findViewById(R.id.img_close_pop);
        Button bt_home = popView.findViewById(R.id.bt_home);
        Button bt_mall = popView.findViewById(R.id.bt_mall);
        Button bt_news = popView.findViewById(R.id.bt_news);
        Button bt_own = popView.findViewById(R.id.bt_own);
        Button bt_goods_car = popView.findViewById(R.id.bt_goods_car);
        Button bt_kefu = popView.findViewById(R.id.bt_kefu);

        img_close_pop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });
        bt_home.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
                EventBus.getDefault().postSticky(new HomePageEvent());
                startActivity(MainActivity.queryIntent(context));
            }
        });
        bt_mall.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
                EventBus.getDefault().postSticky(new GoCartListEvent());
                startActivity(MainActivity.queryIntent(context));
            }
        });
        bt_news.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
                EventBus.getDefault().postSticky(new CartListReloadEvent());
                startActivity(MainActivity.queryIntent(context));
            }
        });
        bt_own.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
                EventBus.getDefault().postSticky(new MinePageEvent());
                startActivity(MainActivity.queryIntent(context));
            }
        });
        bt_goods_car.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
                startActivity(ShoppingCarActivity.queryIntent(context));
            }
        });
        bt_kefu.setOnClickListener(new View.OnClickListener() {//客服
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
                startActivity(OnlineCServiceActivity.getIntent(context, "123456"));
            }
        });


    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_personal_home;
    }


}
